import entities, string

def add(tags):
    
    #if tags == "": return
    
    #tags = [x.strip().lower() for x in tags.split(",")]
    
    for tag in tags:
        
        if tag == "" or tag == None or not tag: continue
        
        if len(tag) > 25 or len(tag) < 3: continue
        
        #tag = string.lowercase(tag)
        #tag = string.capwords(tag)
        
        Tag = entities.Tag.all().filter("name = ", tag).get()
        
        if not Tag: Tag = entities.Tag(name = tag)
        else: Tag.count = Tag.count + 1
        
        Tag.put()
        
def list(limit):
    
    tags = entities.Tag.all().order("-count").fetch(limit)
        
    return tags